package com.rbcs.flow.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.rbcs.borrow.model.Borrow;
import com.rbcs.budget.model.Budget;
import com.rbcs.budget.model.ProjectBudget;
import com.rbcs.reimb.model.Reimb;
import com.rbcs.repay.model.RePay;
import com.systop.common.modules.security.user.model.User;
import com.systop.core.model.BaseModel;

/***
 * 流程表
 * @author Nice
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "flows")
public class Flow extends BaseModel {
	
	private Integer id;
	
	//申请人
	private User proposer;
	
	//最终具体审核人
	private User auditor;
	
	//标题
	private String title;
	
	//创建日期
	private Date createDate;

	//流程结束日期
	private Date endDate;
	
	//状态:[start, stop, end]
	private String status;
	
	//流程节点集合
	private List<Node> nodes = new ArrayList<Node>();
	
	//借款申请表
	private Borrow borrow;

	//还款申请表
	private RePay rePay;
	
	//报销申请表
	private Reimb reimb;
	
	//部门预算
	private Budget budget;
	
	//项目预算
	private ProjectBudget projectBudget;
	
	@Id
	@GeneratedValue(generator = "hibseq")
	@GenericGenerator(name = "hibseq", strategy = "hilo")
	@Column(name = "id", nullable = false)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "proposer_id")
	public User getProposer() {
		return proposer;
	}

	public void setProposer(User proposer) {
		this.proposer = proposer;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "auditor_id")
	public User getAuditor() {
		return auditor;
	}

	public void setAuditor(User auditor) {
		this.auditor = auditor;
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name="create_date")
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	@Column(name = "end_date")
	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "flow")
	@OrderBy("orderId")
	public List<Node> getNodes() {
		return nodes;
	}

	public void setNodes(List<Node> nodes) {
		this.nodes = nodes;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "borrow_id")
	public Borrow getBorrow() {
		return borrow;
	}

	public void setBorrow(Borrow borrow) {
		this.borrow = borrow;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "repay_id")
	public RePay getRePay() {
		return rePay;
	}

	public void setRePay(RePay rePay) {
		this.rePay = rePay;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "reimb_id")
	public Reimb getReimb() {
		return reimb;
	}

	public void setReimb(Reimb reimb) {
		this.reimb = reimb;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "budget_id")
	public Budget getBudget() {
		return budget;
	}

	public void setBudget(Budget budget) {
		this.budget = budget;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "project_budget_id")
	public ProjectBudget getProjectBudget() {
		return projectBudget;
	}

	public void setProjectBudget(ProjectBudget projectBudget) {
		this.projectBudget = projectBudget;
	}
	
}
